--[[
开局N级装备
升级5次后吞噬2件晋升到R
]]

local exiocns = {
    [[core\边框\白.blp]],
    [[core\边框\绿.blp]],
    [[core\边框\蓝.blp]],
    [[core\边框\紫.blp]],
    [[core\边框\黄.blp]],
}

local excel = {}
for _,data in ipairs(load_excel('符文装备.xlsx','1级装备')) do
    local name = data.name
    local level = data.lv
    if name and level<=5 then
        local color,color_text = item_color(level)
        local data = table.copy(data)
        local state = {}
        for a=1,2 do
            local key = data['属性'..a]
            local num = data['数值'..a]
            if key and num then
                state[#state + 1] = {key,num}
                --血量和攻击
                if num>10 then
                    state[#state + 1] = {'基础攻击',num*0.5}
                    state[#state + 1] = {'生命上限',num*5}
                end
            end
        end
        data.color = color
        data.title = color_text:format(data.title or data.name)
        
        data.exiocn = exiocns[level] or exiocns[#exiocns]
        data.base_tip = atts_tip2(state)
        data.state = state
        data.xl_tip = ''
        data.abi_tip = ''
        data.item_class = '符文装备'
        data.tip = [['abi_tip'属性：|n'base_tip'|n|n=================|n随机词条|n'_xl_tips'|n|n'ex_tip']]
        data.shop_tip = [[|cffffcc00点击购买|r|n|n属性：|n'base_tip'|n|n=================|n随机词条|n'_xl_tips'|n|n'ex_tip']]
        
        data.gold = 50 * (2^level)
        if data['升级'] then
            data.abi_tip = ('|cffffcc00点击升级|r(|cffffff00%0.f金币|r)|n|n'):format(data.gold)
        elseif level==5 then
            data['吞噬升级'] = 0
            data.range = 9999
            data.targettype = "物体"
            data.allowtype = '物品'
            data.abi_tip = ('|cffffcc00品质进阶|r(主动)|n点击吞噬2件|cff00ff00Lv5|r的装备后提升至|cff00ff00[R]级装备|r(保留本装备词条)|n|n'):format(data.gold)
        end
        



        ac.lni('item',name,data)
        ac.item(name)

        excel[#excel + 1] = data
    end
end


--[获取随机R级物品名]
function random_item_N(lv)
    local data = {}
    for _,da in ipairs(excel) do
        if lv==nil or da.lv==lv then
            data[#data + 1] = da.name
        end
    end
    local name = table.random(data)
    return name
end


--[5级吞噬升级到R]
ac.game:event '单位-使用物品'(function(_,hero,item,target)
    if item.item_class=='符文装备' and item.on_use==nil then
        local player = hero.owner
        local level = item.lv
        if level<5 then
            local gold = item.gold
            if player:get('金币')<gold then
                show_item_tip(player,item,'金币')
                return
            end
            player:add('金币',-gold)
            item:remove()
            hero:add_item(item['升级'],item:copy_info())

        elseif level==5 then
            --N级Lv5吞噬升级到R
            if target.item_class=='符文装备' and target.lv==5 and target~=item then
                target:remove()
                item['吞噬升级'] = item['吞噬升级'] + (target['吞噬升级'] or 0) + 1
                if item['吞噬升级']==2 then
                    item:remove()
                    local item = hero:add_item(random_item_R(),item:copy_info())
                    show_item_tip(player,item,'刷新')
                else
                    item:set_count(item['吞噬升级'])
                end
            else
                item:set_count(item['吞噬升级'])
                player:send_msg('|cffff0000目标不符！|r')
            end

        end
        
    end
end)


ac.wait(10,function()
    local test_data1 = {}
    for _,data in ipairs(excel) do
        test_data1[#test_data1 + 1] = ac.item.new(data.name)
    end
    ac.game:notify('测试-注册数据','N级装备',test_data1,function(_,player,name)
        local hero = player.hero
        if hero then
            hero:add_item(name)
        end
    end)


end)